﻿namespace SenenFernandez.SmartExtensionMethods
{
    using System;
    using System.Diagnostics;

    /// <summary>
    /// Extension Methods for Reports.
    /// </summary>
    public static class Report
    {
        /// <summary>
        /// Adds the file extension.
        /// </summary>
        public static string AddFileExtension(this string fileName, string defaultFileExtension = ".xlsx")
        {
            string result = fileName;
            if (!result.EndsWith(defaultFileExtension))
            {
                result = String.Format("{0}.{1}", result, defaultFileExtension);
            }
            return result;
        }

        /// <summary>
        /// Opens the file on external application.
        /// </summary>
        public static void OpenFile(this string fileName, string application = "EXCEL")
        {
            var startInfo = new ProcessStartInfo
            {
                FileName = application,
                Arguments = string.Format("\"{0}\"", fileName)
            };
            Process.Start(startInfo);
        }
    }
}
